package com.zdkj.subway.check.controller.subwayRat.conductorDifferences.shoupiaoyuan;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zdkj.common.core.exceltools.MultipartFileToFile;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.subway.check.controller.CommonController;
import com.zdkj.subway.check.dto.SwAuConductorHierarchyAmountDifferenceDto;
import com.zdkj.subway.check.entity.SwAuConductorHierarchyAmountDifference;
import com.zdkj.subway.check.entity.SwParamLine;
import com.zdkj.subway.check.entity.SwParamStation;
import com.zdkj.subway.check.enums.ResultDetailMsg;
import com.zdkj.subway.check.mapper.SwAuConductorHierarchyAmountDifferenceMapper;
import com.zdkj.subway.check.mapper.SwParamLineMapper;
import com.zdkj.subway.check.mapper.SwParamStationMapper;
import com.zdkj.subway.check.result.Result;
import com.zdkj.subway.check.service.SwAuConductorHierarchyAmountDifferenService;
import com.zdkj.subway.check.service.SwAuConductorHierarchyAmountDifferenServices;
import com.zdkj.subway.check.util.DateFormat;
import com.zdkj.subway.check.util.LocalDateConverter;
import com.zdkj.subway.check.util.LocalDateTimeConverter;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/***
 * 线网层级确认-数据协查管理-BOM票款差异协查-BOM系统差异协查-BOM层级差异
 * BOM层级差异（售票员票款层级差异 SW_AU_CONDUCTOR_HIERARCHY_AMOUNT_DIFFERENCE）
 */
@Slf4j
@RestController
@RequestMapping("/checkNew")
public class SwAuConductorHierarchyAmountDifferenCtrl {
    private static final Logger LOGGER = LoggerFactory.getLogger(SwAuConductorHierarchyAmountDifferenService.class);


    @Resource
    private SwAuConductorHierarchyAmountDifferenService swAuConductorHierarchyAmountDifferenService;
    @Autowired
    private SwAuConductorHierarchyAmountDifferenceMapper swAuConductorHierarchyAmountDifferenceMapper;
    @Autowired
    private CommonController commonController;
    @Autowired
    private SwParamLineMapper swParamLineMapper;
    @Autowired
    private SwParamStationMapper swParamStationMapper;
    @Autowired
    private SwAuConductorHierarchyAmountDifferenServices swAuConductorHierarchyAmountDifferenServices;

    /**
     * 售票员票款层级差异 列表
     * @param jsonObject
     * @return
     */
    @RequestMapping("/getSwAuConductorHierarchyAmountDifferenList")
    @ApiOperation(value = "售票员票款层级差异 列表", notes = "售票员票款层级差异 列表")
    public Result getSwAuConductorHierarchyAmountDifferenList(@RequestBody JSONObject jsonObject){
        return swAuConductorHierarchyAmountDifferenService.getSwAuConductorNoticeList(jsonObject);
    }

    /**
     * 售票员票款层级差异 单独查询
     * @param jsonObject
     * @return
     */
    @RequestMapping("/getSwAuConductorHierarchyAmountDifferen")
    @ApiOperation(value = "售票员票款层级差异 单独查询", notes = "售票员票款层级差异 单独查询")
    public Result getSwAuConductorHierarchyAmountDifferen(@RequestBody JSONObject jsonObject){
        return swAuConductorHierarchyAmountDifferenService.getSwAuConductorNotice(jsonObject);
    }

    /**
     * 售票员票款层级差异 修改
     * @param jsonObject
     * @return
     */
    @RequestMapping("/updateSwAuConductorHierarchyAmountDifferenToStatus")
    @ApiOperation(value = "售票员票款层级差异 修改", notes = "售票员票款层级差异 修改")
    @Transactional(rollbackFor = Exception.class)
    public Result updateSwAuConductorHierarchyAmountDifferenToStatus(@RequestBody JSONObject jsonObject){
        try{
            if(null != jsonObject.getJSONArray("ids")){
                JSONArray ids = jsonObject.getJSONArray("ids");
                Map param = JSONObject.parseObject(jsonObject.toString(),Map.class);
                for(Object idObj: ids){
                    Integer id = Integer.valueOf(idObj.toString());
                    SwAuConductorHierarchyAmountDifference swAuConductorHierarchyAmountDifference = new SwAuConductorHierarchyAmountDifference();
                    swAuConductorHierarchyAmountDifference.setId(id);
                    String type = String.valueOf(param.get("type"));
                    if("BOMCengJiCY_001".equals(type)){
                        swAuConductorHierarchyAmountDifference.setJdReplyStatus("1");
                    }
                    else{
                        swAuConductorHierarchyAmountDifference.setQfReplyStatus("1");
                    }
                    swAuConductorHierarchyAmountDifference.setAssistState("3");
                    swAuConductorHierarchyAmountDifferenceMapper.updateById(swAuConductorHierarchyAmountDifference);
                }
                commonController.innerBatch(param);
            }
        }catch (Exception e){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return new Result(ResultDetailMsg.OK);
    }
    /**
     * 售票员票款层级差异 修改
     * @param jsonObject
     * @return
     */
    @RequestMapping("/updateSwAuConductorHierarchyAmountDifferen")
    @ApiOperation(value = "售票员票款层级差异 修改", notes = "售票员票款层级差异 修改")
    public Result updateSwAuConductorHierarchyAmountDifferen(@RequestBody JSONObject jsonObject){
        if(null != jsonObject.getJSONArray("ids")){
            JSONArray ids = jsonObject.getJSONArray("ids");
            for(Object idObj: ids){
                Integer id = Integer.valueOf(idObj.toString());
                this.updateSwAuConductorHierarchyAmountDifferenById(jsonObject,id);
            }
        }else if(null != jsonObject.getInteger("id")){
            Integer id = jsonObject.getInteger("id");
            this.updateSwAuConductorHierarchyAmountDifferenById(jsonObject,id);
        }
        return new Result(ResultDetailMsg.OK);
    }


    /**
     * 售票员票款层级差异 修改
     * @param jsonObject
     * @param id
     */
    private void updateSwAuConductorHierarchyAmountDifferenById(JSONObject jsonObject,Integer id){
        String jdReplyReason = jsonObject.getString("jdReplyReason");
        String jdReplyDetail = jsonObject.getString("jdReplyDetail");
        String qfReplyReason = jsonObject.getString("qfReplyReason");
        String qfReplyDetail = jsonObject.getString("qfReplyDetail");
        SwAuConductorHierarchyAmountDifference swAuConductorHierarchyAmountDifference = new SwAuConductorHierarchyAmountDifference();
        swAuConductorHierarchyAmountDifference.setId(id);
        //回馈售票金额
        if(null != jsonObject.getBigDecimal("replySellAmount")){
            swAuConductorHierarchyAmountDifference.setReplySellAmount(jsonObject.getBigDecimal("replySellAmount").multiply(new BigDecimal(100)));
        }
        //回馈充值金额
        if(null != jsonObject.getBigDecimal("replyInvestAmount")){
            swAuConductorHierarchyAmountDifference.setReplyInvestAmount(jsonObject.getBigDecimal("replyInvestAmount").multiply(new BigDecimal(100)));
        }
        //回馈补票金额
        if(null != jsonObject.getBigDecimal("replyFaretkAmount")){
            swAuConductorHierarchyAmountDifference.setReplyFaretkAmount(jsonObject.getBigDecimal("replyFaretkAmount").multiply(new BigDecimal(100))) ;
        }
        //回馈对比售票金额
        if(null != jsonObject.getBigDecimal("replyComparativeSelltkAmount")){
            swAuConductorHierarchyAmountDifference.setReplyComparativeSelltkAmount(jsonObject.getBigDecimal("replyComparativeSelltkAmount").multiply(new BigDecimal(100)));
        }
        //回馈对比充值金额
        if(null != jsonObject.getBigDecimal("replyComparativeInvestAmount")){
            swAuConductorHierarchyAmountDifference.setReplyComparativeInvestAmount(jsonObject.getBigDecimal("replyComparativeInvestAmount").multiply(new BigDecimal(100)));
        }
        //回馈对比补票金额
        if(null != jsonObject.getBigDecimal("replyComparativeFaretkAmount")){
            swAuConductorHierarchyAmountDifference.setReplyComparativeFaretkAmount(jsonObject.getBigDecimal("replyComparativeFaretkAmount").multiply(new BigDecimal(100))); ;
        }
        swAuConductorHierarchyAmountDifference.setJdReplyReason(jdReplyReason);
        swAuConductorHierarchyAmountDifference.setJdReplyDetail(jdReplyDetail);
        swAuConductorHierarchyAmountDifference.setQfReplyReason(qfReplyReason);
        swAuConductorHierarchyAmountDifference.setQfReplyDetail(qfReplyDetail);
        swAuConductorHierarchyAmountDifferenceMapper.updateById(swAuConductorHierarchyAmountDifference);
    }

    /**
     * 导出
     * @param
     * @return
     */
    @ApiOperation(value = "BOM层级差异机电/BOM票款层级差异清分导出", notes = "BOM层级差异机电/BOM票款层级差异清分导出")
    @GetMapping({"/exportBOMJDorQF"})
    @SysLog("BOM层级差异机电/BOM票款层级差异清分导出")
    public void export(String ids, String tag, SwAuConductorHierarchyAmountDifferenceDto params, HttpServletResponse response) throws ParseException {

        List<SwAuConductorHierarchyAmountDifferenceDto> records = new ArrayList<>();
        if (ids == null || ids.isEmpty()) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("lineCode", params.getLineCode());
            jsonObject.put("stationCode", params.getStationCode());
            jsonObject.put("equipmentNumber", params.getEquipmentNumber());
            jsonObject.put("conductorPersonName", params.getConductorPersonName());
            jsonObject.put("assistTime", params.getAssistTime());
            jsonObject.put("assistStates", params.getAssistState());//导出协查中的和已协查的
            jsonObject.put("qfReplyStatus", params.getQfReplyStatus());
            jsonObject.put("jdReplyStatus", params.getJdReplyStatus());
            jsonObject.put("comparativeType", params.getComparativeType());//1代表SC-LC  2代表LC-ACC
            Result result = swAuConductorHierarchyAmountDifferenService.getSwAuConductorNoticeList(jsonObject);
            Object data = result.getData();
            JSONObject jsonObject1 = JSONObject.parseObject(JSON.toJSONString(data));
            String list = jsonObject1.get("list").toString();
            if (!StringUtils.isEmpty(list)) {
                List<SwAuConductorHierarchyAmountDifference> objects = JSON.parseArray(list, SwAuConductorHierarchyAmountDifference.class);
                objects.stream().forEach(x -> {
                    //导出数据组织
                    SwAuConductorHierarchyAmountDifferenceDto dto = swAuConductorHierarchyAmountDifferenceDtoCommon(x);
                    records.add(dto);

                });

            }
        }else {
            List<String> idLists = new ArrayList<>();
            String[] idParam = ids.split(",");
            for (String s : idParam) {
                idLists.add(s);
            }
            //查询要导出的数据重新组织
            if (CollectionUtils.isNotEmpty(idLists)) {
                List<SwAuConductorHierarchyAmountDifference> objects = swAuConductorHierarchyAmountDifferenceMapper.selectBatchIds(idLists);
                objects.stream().forEach(x -> {
                    SwAuConductorHierarchyAmountDifferenceDto dto = swAuConductorHierarchyAmountDifferenceDtoCommon(x);
                    records.add(dto);
                });
            }

        }
            InputStream excelTemplateIs = null;
            try {
                response.reset(); // 非常重要
                response.setContentType("application/vnd.ms-excel");
                response.setCharacterEncoding("utf-8");
                String fileName = null;
                WriteSheet writeSheet = null;
                if("jidian".equals(tag)){//机电协查
                    // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
                    // {} 代表普通变量 {.} 代表是list的变量
                    //此处getResourceAsStream 用于获取服务器打包后的Excel模板文件流;
                    //如果采用getPath方法获取文件地址本地ieda环境可以获取到，上传到服务器后会失效。采用流可以都生效
                    //String path = this.getClass().getClassLoader().getResource("templates/XXXX.xlsx").getPath();
                    //ExcelWriter excelWriter = EasyExcel.write(ExcelUtils.getOutputStream("XXXX",httpServletResponse)).withTemplate(path).build();
                    fileName = URLEncoder.encode("BOM层级差异机电协查", "UTF-8");
                    excelTemplateIs = this.getClass().getResourceAsStream("/static/excel/export/SwAuBOMCengJiExcelTemplate.xlsx");
                    writeSheet = EasyExcel.writerSheet("BOM层级差异机电协查").build();
                }else {//清分协查
                    fileName = URLEncoder.encode("BOM票款层级差异协查", "UTF-8");
                    excelTemplateIs = this.getClass().getResourceAsStream("/static/excel/export/SwAuBOMAssistExcelTemplate.xlsx");
                    writeSheet = EasyExcel.writerSheet("BOM票款层级差异协查").build();
                }
                response.setHeader("Content-disposition", "attachment;filename=" + fileName + System.currentTimeMillis() + ".xlsx");
                ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream())
                        .registerConverter(new LocalDateTimeConverter()).registerConverter(new LocalDateConverter())
                        .withTemplate(excelTemplateIs).build();
                // 这里注意 入参用了forceNewRow 代表在写入list的时候不管list下面有没有空行 都会创建一行，然后下面的数据往后移动。默认 是false，会直接使用下一行，如果没有则创建。
                // forceNewRow 如果设置了true,有个缺点 就是他会把所有的数据都放到内存了，所以慎用
                // 简单的说 如果你的模板有list,且list不是最后一行，下面还有数据需要填充 就必须设置 forceNewRow=true 但是这个就会把所有数据放到内存 会很耗内存
                // 如果数据量大 list不是最后一行 参照另一个
                FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.FALSE).build();
                //直接写入Excel数据(list是我查询并需导出的数据，并且里面的字段和excel需要导出的字段对应)
                excelWriter.fill(records, fillConfig, writeSheet);
                excelWriter.finish();

            } catch (Exception e) {
                e.printStackTrace();
                log.error("BOM协查导出失败");
            } finally {
                if (excelTemplateIs != null) {
                    try {
                        excelTemplateIs.close();
                    } catch (IOException ioe) {
                        ioe.printStackTrace();
                    }
                }
            }

    }

    /**
     * 数据组织
     * @param x
     */
    private SwAuConductorHierarchyAmountDifferenceDto swAuConductorHierarchyAmountDifferenceDtoCommon(SwAuConductorHierarchyAmountDifference x) {
        //查询线路
        SwParamLine swParamLine = swParamLineMapper.selectOne(Wrappers.<SwParamLine>lambdaQuery().eq(SwParamLine::getCode, x.getLineCode()));
        //查询站点
        SwParamStation swParamStation = swParamStationMapper.selectOne(Wrappers.<SwParamStation>lambdaQuery()
                .eq(SwParamStation::getLineCode, x.getLineCode()).eq(SwParamStation::getCode, x.getStationCode()));
        x.setLineCode(swParamLine.getName());
        x.setStationCode(swParamStation.getName());
        //对比类型
        if ("1".equals(x.getComparativeType())) {
            x.setComparativeType("SC-LC");
        } else {
            x.setComparativeType("LC-ACC");
        }
        x.setSellAmount(getFixed(x.getSellAmount()));// SC/LC售票
        x.setInvestAmount(getFixed(x.getInvestAmount()));// SC/LC充值
        x.setFaretkAmount(getFixed(x.getFaretkAmount()));// SC/LC补票

        x.setReplySellAmount(getFixed(x.getReplySellAmount()));// SC/LC回馈售票
        x.setReplyInvestAmount(getFixed(x.getReplyInvestAmount()));// SC/LC回馈充值
        x.setReplyFaretkAmount(getFixed(x.getReplyFaretkAmount()));// SC/LC回馈补票

        x.setDiffInvestAmount(getFixed(x.getDiffInvestAmount()));//充值差异金额
        x.setDiffSelltkAmount(getFixed(x.getDiffSelltkAmount()));//售票差异金额
        x.setDiffFaretkAmount(getFixed(x.getDiffFaretkAmount()));//补票差异金额

        x.setComparativeSelltkAmount(getFixed(x.getComparativeSelltkAmount()));// LC/ACC售票
        x.setComparativeInvestAmount(getFixed(x.getComparativeInvestAmount()));// LC/ACC充值
        x.setComparativeFaretkAmount(getFixed(x.getComparativeFaretkAmount()));// LC/ACC补票
        x.setReplyComparativeSelltkAmount(getFixed(x.getReplyComparativeSelltkAmount()));// LC/ACC回馈售票
        x.setReplyComparativeInvestAmount(getFixed(x.getReplyComparativeInvestAmount()));// LC/ACC回馈充值
        x.setReplyComparativeFaretkAmount(getFixed(x.getReplyComparativeFaretkAmount()));// LC/ACC回馈补票

        x.setJdReplyReason(StringUtils.isEmpty(x.getJdReplyReason()) ? " " : (x.getJdReplyReason().equals("1") ? "系统原因" : "非系统原因"));
        x.setJdReplyDetail(StringUtils.isEmpty(x.getJdReplyDetail()) ? " " : x.getJdReplyDetail());
        x.setJdReplyStatus(StringUtils.isEmpty(x.getJdReplyStatus()) ? "未回馈" : (x.getJdReplyStatus().equals("0") ? "未回馈" : "已回馈"));

        x.setQfReplyReason(StringUtils.isEmpty(x.getQfReplyReason()) ? " " : (x.getQfReplyReason().equals("1") ? "系统原因" : "非系统原因"));
        x.setQfReplyDetail(StringUtils.isEmpty(x.getQfReplyDetail()) ? " " : x.getQfReplyDetail());

        SwAuConductorHierarchyAmountDifferenceDto dto = new SwAuConductorHierarchyAmountDifferenceDto();
        BeanUtils.copyProperties(x,dto);
        dto.setSettleDate(DateFormat.DateTurnLocalDate(x.getSettleTime()));//收入日期
        if(x.getJdReplyTime()!=null){
            dto.setJdReplyDateTime(DateFormat.DateTurnLocalDateTime(x.getJdReplyTime()));//机电回馈时间
        }
        return dto;
    }

    /**
     * BOM层级差异机电/BOM票款层级差异清分导入
     * @param file
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "BOM层级差异机电/BOM票款层级差异清分导入", notes = "BOM层级差异机电/BOM票款层级差异清分导入")
    @SysLog("BOM层级差异机电/BOM票款层级差异清分导入")
    @PostMapping({ "/importBOMJDorQF" })
    public R importTVM(@RequestParam("file") final MultipartFile file) throws Exception {

        final File excelFile = MultipartFileToFile.multipartFileToFile(file);
        List<Map<Integer, String>> listMap = EasyExcel.read(excelFile).sheet().headRowNumber(2).doReadSync();
        if (CollectionUtil.isNotEmpty(listMap)) {
            List<SwAuConductorHierarchyAmountDifference> conductorHierarchyList = new ArrayList<>();
            MultipartFileToFile.delteTempFile(excelFile);
            for (int m = 0; m < listMap.size(); m++) {
                Map<Integer, String> data = listMap.get(m);
                // 返回每条数据的键值对 key表示所在的列位置 value表示所在列的值
                LOGGER.info("读取到数据:{}", JSON.toJSONString(data));

                SwAuConductorHierarchyAmountDifference conductorHierarchy = new SwAuConductorHierarchyAmountDifference();
                conductorHierarchy.setId(Integer.parseInt(data.get(0)));//主键id
                conductorHierarchy.setReplySellAmount(getData(data.get(9)));//SC/LC回馈售票
                conductorHierarchy.setReplyInvestAmount(getData(data.get(11)));//SC/LC回馈充值
                conductorHierarchy.setReplyFaretkAmount(getData(data.get(13)));//SC/LC回馈补票
                if("SC-LC".equals(data.get(7))){//机电回馈
                    if ("系统原因".equals(data.get(17))) {
                        conductorHierarchy.setJdReplyReason("1");//回馈原因
                    }
                    if ("非系统原因".equals(data.get(17)))  {
                        conductorHierarchy.setJdReplyReason("2");//回馈原因
                    }
                    conductorHierarchy.setJdReplyDetail(data.get(18));//回馈描述
                    //conductorHierarchy.setJdReplyStatus("1");//已回馈 改为手动提交
                }else {//清分回馈
                    conductorHierarchy.setReplyComparativeSelltkAmount(getData(data.get(15)));//LC/ACC回馈售票
                    conductorHierarchy.setReplyComparativeInvestAmount(getData(data.get(17)));//LC/ACC回馈充值
                    conductorHierarchy.setReplyComparativeFaretkAmount(getData(data.get(19)));//LC/ACC回馈补票
                    if ("系统原因".equals(data.get(20))) {
                        conductorHierarchy.setQfReplyReason("1");//回馈原因
                    }
                    if ("非系统原因".equals(data.get(20))) {
                        conductorHierarchy.setQfReplyReason("2");//回馈原因
                    }
                    conductorHierarchy.setQfReplyDetail(data.get(21));//回馈描述
                    //conductorHierarchy.setQfReplyStatus("1");//已回馈 改为手动提交
                }

                conductorHierarchyList.add(conductorHierarchy);
            }
            //  增加根据id批量更新回馈信息方法
            swAuConductorHierarchyAmountDifferenServices.updateBatchById(conductorHierarchyList);
        }
        return R.ok();
    }


    /**
     * 金额转换 乘100
     *
     * @param money
     * @return
     */
    private BigDecimal getData(String money){
        try {
            BigDecimal num = new BigDecimal("100");
            BigDecimal itemMoney = new BigDecimal(money).setScale(2, BigDecimal.ROUND_HALF_UP);
            itemMoney = itemMoney.multiply(num);
            return itemMoney;

        } catch (Exception e) {
            return new  BigDecimal("0.00");
        }

    }

    /**
     * 金额转换 除100
     *
     * @param money
     * @return
     */
    private BigDecimal getFixed(BigDecimal money){
        try {
            BigDecimal num = new BigDecimal("100");
            BigDecimal itemMoney = money.divide(num);
            itemMoney = itemMoney.setScale(2, BigDecimal.ROUND_HALF_UP);
            return itemMoney;

        } catch (Exception e) {
            return new  BigDecimal("0.00");
        }

    }

    /**
     * BOM层级差异机电协查 撤回
     * @param
     * @return
     */
    @RequestMapping("revokeBomCengJi")
    public R revokeBomCengJi(String ids) {
        List<SwAuConductorHierarchyAmountDifference> hierarchyAmountDifferences = swAuConductorHierarchyAmountDifferenceMapper.selectBatchIds(Arrays.asList(ids.split(",")));
        if(CollectionUtil.isNotEmpty(hierarchyAmountDifferences)){
            for(SwAuConductorHierarchyAmountDifference hierarchyAmountDifference:hierarchyAmountDifferences){
                if("1".equals(hierarchyAmountDifference.getReplaceStatus())){
                    return R.failed("已经替换的数据不能撤回！");
                }
                SwAuConductorHierarchyAmountDifference s=new SwAuConductorHierarchyAmountDifference();
                s.setId(hierarchyAmountDifference.getId());
                s.setJdReplyStatus("0");//机电回馈状态改为0，未回馈
                s.setAssistState("2");//协查状态改为2，待协查
                swAuConductorHierarchyAmountDifferenceMapper.updateById(s);
            }
        }
        return R.ok();
    }
}
